package com.qcby.onlinelearningplatform.Service.Impl;

import com.qcby.onlinelearningplatform.Dao.StudentDao;
import com.qcby.onlinelearningplatform.Entity.*;
import com.qcby.onlinelearningplatform.Service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {


    @Autowired
    public StudentDao studentDao;


    @Override
    public Student login(String s_sno) {
        return this.studentDao.login(s_sno);
    }

    @Override
    public List<StudentChannel> studentChannel() {
        return this.studentDao.studentChannel();
    }

    @Override
    public List<Topic> studentTopic(Integer pageSize, Integer pageIndex) {
        pageIndex = pageSize * (pageIndex - 1);
        return this.studentDao.studentTopic(pageSize,pageIndex);
    }

    @Override
    public List<Topic> topicLikeTitle(Topic topic) {
        Topic topic1 = new Topic();
        topic1.setTitle("%" + topic.getTitle() + "%");
        topic1.setPageSize(topic.getPageSize());
        topic1.setPageIndex((topic.getPageIndex()-1)*topic.getPageSize());

        return this.studentDao.topicLikeTitle(topic1);
    }

    @Override
    public int insertTopic(Topic topic) {
        return this.studentDao.insertTopic(topic);
    }

    @Override
    public List<ClassFile> studentClassfile(Integer pageSize, Integer pageIndex) {
        pageIndex = pageSize * (pageIndex - 1);
        return this.studentDao.studentClassfile(pageSize,pageIndex);
    }

    @Override
    public List<ClassFile> classfileLikeName(ClassFile classFile) {
        ClassFile classFile1 = new ClassFile();
        classFile1.setFileName("%" + classFile.getFileName()+ "%");
        classFile1.setPageSize(classFile.getPageSize());
        classFile1.setPageIndex((classFile.getPageIndex()-1)*classFile.getPageSize());

        return this.studentDao.classfileLikeName(classFile1);
    }

    @Override
    public List<HomeWork> studentHomework(Integer pageSize, Integer pageIndex) {
        pageIndex = pageSize * (pageIndex -1);
        return this.studentDao.studentHomework(pageSize,pageIndex);
    }

    @Override
    public List<HomeWork> homeworkLikeName(HomeWork homeWork) {
        HomeWork homeWork1 = new HomeWork();
        homeWork1.setWorkName("%" + homeWork.getWorkName() + "%");
        homeWork1.setPageIndex((homeWork.getPageIndex()-1)*homeWork.getPageSize());
        homeWork1.setPageSize(homeWork.getPageSize());
        return this.studentDao.homeworkLikeName(homeWork1);
    }


}
